package org.rc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.rc.entity.RoomDev;
import org.rc.mapper.RoomDevMapper;
import org.rc.service.RoomDevService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class RoomDevServiceImpl extends ServiceImpl<RoomDevMapper, RoomDev> implements RoomDevService {

    @Override
    public void addRoomDevs(List<RoomDev> roomDevs) {
        this.saveBatch(roomDevs);
    }

    @Override
    public void deleteRoomDevs(Long roomId) {
        QueryWrapper<RoomDev> roomDevQueryWrapper = new QueryWrapper<>();
        roomDevQueryWrapper.eq("room_id",roomId);
        this.remove(roomDevQueryWrapper);
    }

    @Override
    public List<RoomDev> getBindRoomDev(Integer type) {
        QueryWrapper<RoomDev> roomDevQueryWrapper = new QueryWrapper<>();
        roomDevQueryWrapper.eq("dev_type",type);
        return this.list(roomDevQueryWrapper);
    }

    @Override
    public void deleteRoomsDev(List<Long> roomIds) {
        QueryWrapper<RoomDev> roomDevQueryWrapper = new QueryWrapper<>();
        roomDevQueryWrapper.in("room_id",roomIds);
        this.remove(roomDevQueryWrapper);
    }

    @Override
    public List<RoomDev> getDevsByRoomId(Long roomId) {
        QueryWrapper<RoomDev> roomDevQueryWrapper = new QueryWrapper<>();
        roomDevQueryWrapper.eq("room_id",roomId);
        return this.list(roomDevQueryWrapper);
    }

    @Override
    public List<RoomDev> getByRoomIds(List<Long> roomIds) {
        QueryWrapper<RoomDev> roomDevQueryWrapper = new QueryWrapper<>();
        roomDevQueryWrapper.in("room_id",roomIds);
        return this.list(roomDevQueryWrapper);
    }

    @Override
    public List<RoomDev> getBindRoomDevByTypeAndDevIds(Integer type, List<Long> devIds) {
        QueryWrapper<RoomDev> roomDevQueryWrapper = new QueryWrapper<>();
        roomDevQueryWrapper.eq("dev_type",type).in("dev_id",devIds);
        return this.list(roomDevQueryWrapper);
    }

    @Override
    public RoomDev getRoomDevByTypeAndDevId(Integer type, Long devId) {
        QueryWrapper<RoomDev> roomDevQueryWrapper = new QueryWrapper<>();
        roomDevQueryWrapper.eq("dev_type",type).eq("dev_id",devId);
        return getOne(roomDevQueryWrapper);
    }

    @Override
    public List<RoomDev> getRoomDevByRoomIdAndDevId(Integer type, Long roomId) {
        QueryWrapper<RoomDev> roomDevQueryWrapper = new QueryWrapper<>();
        roomDevQueryWrapper.eq("dev_type",type).eq("room_id",roomId);
        return list(roomDevQueryWrapper);
    }

    @Override
    public void deleteByTypeAndId(Integer type, Long id) {
        QueryWrapper<RoomDev> roomDevQueryWrapper = new QueryWrapper<>();
        roomDevQueryWrapper.eq("dev_type",type).eq("dev_id",id);
        this.remove(roomDevQueryWrapper);
    }

    @Override
    public void deleteByTypeAndIds(Integer type, List<Long> ids) {
        QueryWrapper<RoomDev> roomDevQueryWrapper = new QueryWrapper<>();
        roomDevQueryWrapper.eq("dev_type",type).in("dev_id",ids);
        this.remove(roomDevQueryWrapper);
    }
}
